<div class="inside">
  <aside class="navigationPanel" style="margin-top: -28px;padding-top: 20px">
     
     <div class="tree pagesLinks">
        <ul>
           <ul>
              <li> <a href="<?php echo $baseurl.'campaign-agency/dia-diem.html'?>" class="active">Địa điểm</a> </li>
              <li> <a href="<?php echo $baseurl.'campaign-agency/cho-duyet.html'?>">Chiến dịch chờ duyệt</a> </li>
              <li> <a href="<?php echo $baseurl.'campaign-agency/gui-duyet.html'?>">Chiến dịch đã gửi duyệt</a> </li>
              <li> <a href="<?php echo $baseurl.'campaign-agency/dang-chay.html'?>">Chiến dịch đang chạy</a> </li>
              <li> <a href="<?php echo $baseurl.'campaign-agency/khac.html'?>">Chiến dịch đang khóa</a> </li>
           </ul>
        </ul>
     </div>
  </aside>
  <div class="contentPanel" style="height: 542px;">
     <div class="pages" id="profile">
        <div class="profile-edit-form" style="margin-top: -70px;">
              <div class="contentBox switcher" style="height: 100%;">
                    <div style="width: 100%;float: left;color: #777;">
                        <h3 style="float: left;width: 93%;">Danh sách chiến dịch</h3>
                        <button onclick="window.location='<?php echo site_url('campaign-agency/dia-diem')?>'" style="margin-top: 16px;padding: 8px;background: rgb(7, 137, 205);border: none;color: #FFF;">Quay lại</button>
                     </div>
                     <div style="clear: both;"></div>
                    <div class="insideContentBox">
                          <div class="wicity">
                    			<table >
                    				<tr> 
                    					<td style="width: 7%;">
                    						STT
                    					</td>
                    					<td >
                    						Tên chiến dịch
                    					</td>
                                        <td>
                    						Link chiến dịch
                    					</td>
                                        <td>
                    						Khách hàng
                    					</td>
                    					<td style="width: 15%;">
                    						Ngày bắt đầu
                    					</td>
                                        <td style="width: 15%;">
                    						Ngày kết thúc
                    					</td>
                                        <td>
                    						Trạng thái
                    					</td>
                                        <td>
                    						Tác vụ
                    					</td>
                    				</tr>
                                    <?php if(!in_array($data, array(null, '', '0'))):?>
                                        <?php $i = 1; foreach($data AS $el=>$le):?>
                                        <tr> 
                        					<td style="text-align: center;">
                        						<?php if($page != 0){
                                                    echo $stt = ($page-1)*$per_page + $i;
                                                }else{
                                                    echo $stt = $page + $i ;
                                                }?>
                        					</td>
                        					<td >
                        						<?php echo $le->title;?>
                        					</td>
                                            
                                            <td>
                        						<?php echo $le->link_campaign ? $le->link_campaign : 'Chưa có link'?>
                        					</td>
                                            <td >
                        						<?php echo $le->username;?>
                        					</td>
                        					<td>
                        						<?php echo $le->time_start;?>
                        					</td>
                                            <td>
                        						<?php echo $le->time_end?>
                        					</td>
                                            <td class="status">
                    						<?php echo $fview->status_campaign($le->active);?>
                        					</td>
                                            <td>
                        						<a href="<?php echo site_url('view-campaign-user').'?id='.$le->cid?>">Xem chi tiết</a>
                        					</td>
                                            <!--td>
                        						<?php if($le->active == 0):?>
                                                    <a data-id="<?php echo $le->cid;?>" class="bt-action send-approval-campaign">Gửi duyệt</a>
                                                <?php elseif($le->active == 1):?>
                                                    <a data-id="<?php echo $le->cid;?>" class="bt-action cancel-campaign">Hủy bỏ</a>
                                                <?php elseif($le->active == 2):?>
                                                    <a data-id="<?php echo $le->cid;?>" class="bt-action lock-campaign">Khóa</a>
                                                <?php elseif($le->active == 3 || $le->active == 4):?>
                                                    <a data-id="<?php echo $le->cid;?>" class="bt-action restore-campaign">Khôi phục</a>
                                                <?php endif;?>
                                                
                                                
                        					</td-->
                        				</tr>
                                        <?php $i++; endforeach;?>
                                    <?php else:?>
                                        <tr> 
                                            <td colspan="7">
                        						Không tìm thấy bất kỳ chiến dịch nào.
                        					</td>
                        				</tr>
                                    <?php endif;?>
                    			</table>
                    		</div>
                            <div class="pagination">
                                <?php echo $this->pagination->create_links();?> 
                            </div> 
                    </div>
              </div>
        </div>
     </div>
  </div>
</div> 
<style>
body.flash-permanent .contentPanel {
    padding: 100px 0px 18px !important;
}
.admin .contentBox .insideContentBox {
background: white;
padding: 26px 0px !important;
}
a{
    cursor: pointer;
}
</style>

<script type="text/javascript">
    $(document).ready(function(){
        $('.bt-action').on('click', function(){
            var _this = $(this);
            var id = $(this).data('id');
            if(_this.hasClass('send-approval-campaign')){
                $.ajax({
                type: "GET",
                url: baseUrl + "send-approval-campaign",
                data: ({id: id}),
                success: function(data){
                    if(data == 200){
                        _this.removeClass('send-approval-campaign').addClass('cancel-campaign');
                        _this.html("Hủy bỏ");
                        _this.parents('tr').find('.status').html("Đã gửi duyệt");
                    }
                }
            }); 
            }else if(_this.hasClass('cancel-campaign')){
                $.ajax({
                type: "GET",
                url: baseUrl + "cancel-campaign",
                data: ({id: id}),
                success: function(data){
                    if(data == 200){
                        _this.removeClass('cancel-campaign').addClass('restore-campaign')                        
                        _this.html("Khôi phục");
                        _this.parents('tr').find('.status').html("Đã xóa");
                    }
                }
            }); 
            }else if(_this.hasClass('lock-campaign')){
                $.ajax({
                type: "GET",
                url: baseUrl + "lock-campaign",
                data: ({id: id}),
                success: function(data){
                    if(data == 200){
                        _this.removeClass('lock-campaign').addClass('restore-campaign');
                        _this.html("Khôi phục");
                        _this.parents('tr').find('.status').html("Tạm khóa");
                    }
                }
            }); 
            }else if(_this.hasClass('restore-campaign')){
                $.ajax({
                type: "GET",
                url: baseUrl + "restore-campaign",
                data: ({id: id}),
                success: function(data){
                    var parse = JSON.parse(data);
                    if(parse.status == 200)
                    {
                        if(parse.active == 0){
                            var class_add = 'send-approval-campaign'; 
                            var html_add = 'Gửi duyệt';
                            var status_add = 'Chờ duyệt';
                        }else if(parse.active == 1){
                            var class_add = 'cancel-campaign'; 
                            var html_add = 'Hủy bỏ';
                            var status_add = 'Đã gửi duyệt';
                        }else if(parse.active == 2){
                            var class_add = 'lock-campaign'; 
                            var html_add = 'Khóa';
                            var status_add = 'Đã duyệt';
                        }
                        _this.removeClass('restore-campaign').addClass(class_add);
                        _this.html(html_add);
                        _this.parents('tr').find('.status').html(status_add);
                    }
                }
            }); 
            }
            return false;
        });
    });
</script>